package cn.itcast.controller;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.net.InetSocketAddress;
import java.net.Proxy;
import java.util.ArrayList;
import java.util.List;

/**
 * Author:zhansan
 * Date:2023/3/19
 * Description:
 */
@RestController
@Slf4j
public class EightBox {
    String createOrderUrl="https://8box.yunshubo.com/api/new_buy";
    Integer goodsId=1;
    private static List<IpBean> list=new ArrayList<>();
    private static List<String> tokenList=new ArrayList<>();
    @RequestMapping("/createBox")
    public String hello3(@RequestParam(value = "num",defaultValue = "1000") Integer num) {

        return "test";
    }
    public void confireOrder(Proxy proxy,String token){
        try{
            createOrder(proxy,token);
        }catch (Exception e){
            log.error("#####创建订单失败####"+e.getMessage()+"###"+token);
        }
    }
    public void createOrder(Proxy proxy,String token) throws InterruptedException {
        JSONObject requestJson = new JSONObject();
        requestJson.putOnce("id", goodsId);
        requestJson.putOnce("is_integral", false);
        requestJson.putOnce("payment", "money");
        requestJson.putOnce("result", "{}");
        requestJson.putOnce("transaction_password", "891223");
        requestJson.putOnce("work_id", "3");
        proxy=null;
        String requestParam = requestJson.toString();
        String result = HttpRequest.post(createOrderUrl).setProxy(proxy).timeout(3000).
                body(requestParam)
                .header("Authorization",token)
                .execute().body();
        log.info("####支付结果######"+result+"########"+token);
    }
    public void addToken(){
        tokenList.add("Bearer 13198@4198f16fd449a55bb0695f850aa8ea7d0a4d99e6");
    }
}
